
// Source File Name:   InternalFactory.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.MessageUtils;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.AD;
import com.sunwayhorizo.health.hl7.datatypes.ADXP;
import com.sunwayhorizo.health.hl7.datatypes.BAG_AD;
import com.sunwayhorizo.health.hl7.datatypes.BAG_EN;
import com.sunwayhorizo.health.hl7.datatypes.BAG_TEL;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CD;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.EN;
import com.sunwayhorizo.health.hl7.datatypes.GTS;
import com.sunwayhorizo.health.hl7.datatypes.II;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.LIST_INT;
import com.sunwayhorizo.health.hl7.datatypes.OID;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.RTO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.SET_CD;
import com.sunwayhorizo.health.hl7.datatypes.SET_CE;
import com.sunwayhorizo.health.hl7.datatypes.SET_CS;
import com.sunwayhorizo.health.hl7.datatypes.SET_II;
import com.sunwayhorizo.health.hl7.datatypes.SET_PQ;
import com.sunwayhorizo.health.hl7.datatypes.SET_RTO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TEL;
import com.sunwayhorizo.health.hl7.datatypes.UID;
import com.sunwayhorizo.health.hl7.common.RimDataTypeException;

//import com.sunwayhorizo.health.ctb.hl7.common.RimDataTypeException;

//            ADImpl, BAG_ADImpl, BAG_ENImpl, BAG_TELImpl,
//            BLImpl, CEImpl, CSImpl, GTSNullImpl, 
//            IIImpl, INTImpl, LIST_INTAdapterImpl, NullFlavorImpl, 
//            OIDImpl, SET_CDImpl, SET_CEImpl, SET_CSImpl, 
//            SET_IIImpl, SET_PQImpl, SET_RTO_PQImpl, STImpl, 
//            TELImpl

public class InternalFactory
{

    public static final String RCS_ID = "$Header: InternalFactory.java 1.01 2006/05/13 15:03:58 atomlins noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: InternalFactory.java 1.0 2006/05/13 15:03:58 atomlins noship $", "com.sunwayhorizo.health.hl7.datatypes.common");
    private static final String FACTORY_CODE = "CTB_CORE_DATATYPE_FACTORY";
    private static final String MANDATORY_MESSAGE = "Mandatory property &PARAM of data type &CLASS must be supplied to the factory method";
    private static final String FACTORY_MESSAGE = "An error occurred while constructing a new instance of &CLASS: &CAUSE";
    private static final String CLASS_KEY = "CLASS";
    private static final String METHOD_KEY = "METHOD";
    private static final String PARAM_KEY = "PARAM";
    private static final String CAUSE_KEY = "CAUSE";
    public static final BL NULL_BL;
    public static final ST NULL_ST;
    public static final CS NULL_CS;
    public static final CE NULL_CE;
    public static final SET_II NULL_SET_II;

    public static BL newBL(boolean flag)
    {
        return BLImpl.valueOf(flag);
    }

    public static ST newST(String s)
    {
        return STImpl.valueOf(s);
    }

    public static CS newCS(String s)
    {
        return CSImpl.valueOf(s);
    }

    public static CE newCE(String s, String s1)
    {
        return (CE)CEImpl.valueOf(s, s1);
    }

    public static II newII(UID uid, ST st, ST st1)
    {
        return IIImpl.valueOf(uid, st, st1);
    }

    public static INT newINT(int i)
    {
        return INTImpl.valueOf(i);
    }

    public static OID newOID(String s)
    {
        return OIDImpl.valueOf(s);
    }

    public static TEL newTEL(String s, String s1, GTS gts, SET_CS set_cs, String s2)
    {
        CS cs = s != null ? CSImpl.valueOf(s) : CSImpl.nullCS(NullFlavorImpl.NI);
        ST st = s1 != null ? STImpl.valueOf(s1) : STImpl.nullST(NullFlavorImpl.NI);
        GTS gts1 = gts != null ? gts : GTSNullImpl.nullGTS(NullFlavorImpl.NI);
        SET_CS set_cs1 = set_cs != null ? set_cs : SET_CSImpl.nullSET_CS(NullFlavorImpl.NI);
        return TELImpl.valueOf(cs, st, gts1, set_cs1, s2);
    }

    public static AD newAD(ADXP aadxp[], GTS gts, SET_CS set_cs, String s, ST st)
        throws Hl7Exception
    {
        GTS gts1 = gts != null ? gts : GTSNullImpl.nullGTS(NullFlavorImpl.NI);
        SET_CS set_cs1 = set_cs != null ? set_cs : SET_CSImpl.nullSET_CS(NullFlavorImpl.NI);
        try
        {
            return ADImpl.valueOf(aadxp, set_cs1, gts1, s, st);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("AD", throwable);
        }
    }

    public static SET_CD newSET_CD(CD acd[])
        throws Hl7Exception
    {
        if(acd == null)
            return nullSET_CD(NullFlavorImpl.NI);
        try
        {
            return SET_CDImpl.valueOf(acd);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<CD>", throwable);
        }
    }

    public static SET_CD newSET_CD(CD cd)
        throws Hl7Exception
    {
        if(cd == null || cd.isNull().isTrue())
            return nullSET_CD(NullFlavorImpl.NI);
        try
        {
            return SET_CDImpl.valueOf(cd);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<CD>", throwable);
        }
    }

    public static SET_CD nullSET_CD(CS cs)
    {
        return SET_CDImpl.nullSET_CD(cs);
    }

    public static SET_II newSET_II(II aii[])
        throws Hl7Exception
    {
        if(aii == null)
            return nullSET_II(NullFlavorImpl.NI);
        try
        {
            return SET_IIImpl.valueOf(aii);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<II>", throwable);
        }
    }

    public static SET_II nullSET_II(CS cs)
    {
        return SET_IIImpl.nullSET_II(cs);
    }

    public static SET_II newSET_II(II ii)
        throws Hl7Exception
    {
        if(ii == null || ii.isNull().isTrue())
            return nullSET_II(NullFlavorImpl.NI);
        try
        {
            return SET_IIImpl.valueOf(ii);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<II>", throwable);
        }
    }

    public static SET_CE newSET_CE(CE ce)
        throws Hl7Exception
    {
        if(ce == null || ce.isNull().isTrue())
            return nullSET_CE(NullFlavorImpl.NI);
        try
        {
            return SET_CEImpl.valueOf(ce);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<CE>", throwable);
        }
    }

    public static SET_CE nullSET_CE(CS cs)
    {
        return SET_CEImpl.nullSET_CE(cs);
    }

    public static BAG_EN newBAG_EN(EN en)
        throws Hl7Exception
    {
        if(en == null || en.isNull().isTrue())
            return nullBAG_EN(NullFlavorImpl.NI);
        try
        {
            return BAG_ENImpl.valueOf(en);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("BAG<EN>", throwable);
        }
    }

    public static BAG_EN nullBAG_EN(CS cs)
    {
        return BAG_ENImpl.nullBAG_EN(cs);
    }

    public static SET_PQ newSET_PQ(PQ pq)
        throws Hl7Exception
    {
        if(pq == null || pq.isNull().isTrue())
            return nullSET_PQ(NullFlavorImpl.NI);
        try
        {
            return SET_PQImpl.valueOf(pq);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<PQ>", throwable);
        }
    }

    public static SET_PQ nullSET_PQ(CS cs)
    {
        return SET_PQImpl.nullSET_PQ(cs);
    }

    public static BAG_TEL newBAG_TEL(TEL tel)
        throws Hl7Exception
    {
        if(tel == null || tel.isNull().isTrue())
            return nullBAG_TEL(NullFlavorImpl.NI);
        try
        {
            return BAG_TELImpl.valueOf(tel);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("BAG<TEL>", throwable);
        }
    }

    public static BAG_TEL nullBAG_TEL(CS cs)
    {
        return BAG_TELImpl.nullBAG_TEL(cs);
    }

    public static BAG_AD newBAG_AD(AD ad)
        throws Hl7Exception
    {
        if(ad == null || ad.isNull().isTrue())
            return nullBAG_AD(NullFlavorImpl.NI);
        try
        {
            return BAG_ADImpl.valueOf(ad);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("BAG<AD>", throwable);
        }
    }

    public static BAG_AD nullBAG_AD(CS cs)
    {
        return BAG_ADImpl.nullBAG_AD(cs);
    }

    public static LIST_INT newLIST_INT(INT aint[])
        throws Hl7Exception
    {
        if(aint == null || aint.length == 0)
            return nullLIST_INT(NullFlavorImpl.NI);
        try
        {
            return LIST_INTAdapterImpl.valueOf(aint);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("LIST<INT>", throwable);
        }
    }

    public static LIST_INT newLIST_INT(INT int1)
        throws Hl7Exception
    {
        if(int1 == null || int1.isNull().isTrue())
            return nullLIST_INT(NullFlavorImpl.NI);
        try
        {
            return LIST_INTAdapterImpl.valueOf(int1);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("LIST<INT>", throwable);
        }
    }

    public static LIST_INT nullLIST_INT(CS cs)
    {
        return LIST_INTAdapterImpl.nullLIST_INT(cs);
    }

    public static SET_RTO_PQ newSET_RTO_PQ(RTO_PQ rto_pq)
        throws Hl7Exception
    {
        if(rto_pq == null || rto_pq.isNull().isTrue())
            return nullSET_RTO_PQ(NullFlavorImpl.NI);
        try
        {
            return SET_RTO_PQImpl.valueOf(rto_pq);
        }
        catch(Throwable throwable)
        {
            throw newFactoryException("SET<RTO_PQ>", throwable);
        }
    }

    public static SET_RTO_PQ nullSET_RTO_PQ(CS cs)
    {
        return SET_RTO_PQImpl.nullSET_RTO_PQ(cs);
    }

    private static Hl7Exception newFactoryException(String s, Throwable throwable)
    {
        String as[] = {
            "CLASS", "CAUSE"
        };
        String as1[] = {
            s, throwable.getMessage()
        };
        String s1 = MessageUtils.getMessage("An error occurred while constructing a new instance of &CLASS: &CAUSE", as, as1);
        return new RimDataTypeException("CTB_CORE_DATATYPE_FACTORY", s1, throwable);
    }

    public InternalFactory()
    {
    }

    static 
    {
        NULL_BL = BLImpl.nullBL(NullFlavorImpl.NI);
        NULL_ST = STImpl.nullST(NullFlavorImpl.NI);
        NULL_CS = CSImpl.nullCS(NullFlavorImpl.NI);
        NULL_CE = CEImpl.nullCE(NullFlavorImpl.NI);
        NULL_SET_II = SET_IIImpl.nullSET_II(NullFlavorImpl.NI);
    }
}
